<UserControl x:Class="LogGrok.LogView.LogView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:be="clr-namespace:LogGrok.Infrastructure.Behaviors;assembly=LogGrok.Infrastructure"
             xmlns:controls="clr-namespace:LogGrok.Controls;assembly=LogGrok.Controls"
             xmlns:dec="clr-namespace:LogGrok.Infrastructure.Decoration;assembly=LogGrok.Infrastructure"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:index="clr-namespace:LogGrok.IndexedFilter;assembly=LogGrok.IndexedFilter"
             xmlns:infra="clr-namespace:LogGrok.Infrastructure;assembly=LogGrok.Infrastructure"
             xmlns:infracontrols="clr-namespace:LogGrok.Infrastructure.Controls;assembly=LogGrok.Infrastructure"
             xmlns:interaction="clr-namespace:LogGrok.Infrastructure.Interaction;assembly=LogGrok.Infrastructure"
             xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Interactivity.InteractionRequest;assembly=Microsoft.Practices.Prism.Interactivity"
             xmlns:tookit="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
             be:RoutedCommandBehavior.RoutedCommandToCommandBinding="{be:RoutedCommandToCommandBinding Command={Binding GotoLine},
                                                                                                       RoutedCommand={x:Static infra:RoutedCommands.GotoLineCommand}}"
             controls:FindRoutedCommandBehavior.IsRoutedCommandRoot="True"
             infra:PaneConentAttachedProperties.PaneTitle="{Binding Title}"
             infra:PaneConentAttachedProperties.PaneTitleToolTip="{Binding Header}">
    <UserControl.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Styles/ListViewItemStyle.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
            <UserControl x:Key="CtrlGDialog">
                <Grid Background="#AAAAAAAA">
                    <Grid.InputBindings>
                        <KeyBinding Key="Enter" Command="{x:Static interaction:DialogInteractionAction.OkCommand}" />
                        <KeyBinding Key="Escape" Command="{x:Static interaction:DialogInteractionAction.CancelCommand}" />
                    </Grid.InputBindings>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Border Grid.Row="1"
                            Grid.Column="1"
                            BorderBrush="DarkGray"
                            BorderThickness="2">
                        <StackPanel Background="{x:Static SystemColors.WindowBrush}">
                            <tookit:IntegerUpDown x:Name="UpDown"
                                                  Width="200"
                                                  Margin="10"
                                                  Minimum="0"
                                                  Watermark="Line number"
                                                  be:SetFocusBehaivor.Focused="{Binding IsVisible,
                                                                                        RelativeSource={RelativeSource Self}}"
                                                  Value="{Binding LineNumber,
                                                                  UpdateSourceTrigger=PropertyChanged}" />
                            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                                <Button Width="80"
                                        Margin="5, 10, 5, 10"
                                        Command="{x:Static interaction:DialogInteractionAction.OkCommand}"
                                        Content="Ok" />
                                <Button Width="80"
                                        Margin="5, 10, 10, 10"
                                        Command="{x:Static interaction:DialogInteractionAction.CancelCommand}"
                                        Content="Cancel" />
                            </StackPanel>

                        </StackPanel>
                    </Border>
                </Grid>
            </UserControl>
        </ResourceDictionary>

    </UserControl.Resources>
    <i:Interaction.Triggers>
        <prism:InteractionRequestTrigger SourceObject="{Binding GotoLineRequest}">
            <interaction:DialogInteractionAction DialogView="{StaticResource CtrlGDialog}" />
        </prism:InteractionRequestTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <ProgressBar x:Name="progressBar"
                     Height="3"
                     HorizontalAlignment="Stretch"
                     Value="{Binding Progress}">
            <ProgressBar.Resources>
                <Style BasedOn="{StaticResource ResourceKey=MetroProgressBar}" TargetType="{x:Type ProgressBar}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Progress}" Value="100">
                            <Setter Property="ProgressBar.Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ProgressBar.Resources>
        </ProgressBar>
        <dec:DecoratorContentControl Grid.Row="1" infra:AvalonRegion.Name="MainDocumentView">
            <infra:ListView FontFamily="Consolas"
                            IsTextSearchEnabled="False"
                            ItemContainerStyle="{StaticResource ItemStyle}"
                            ItemsSource="{Binding VirtualLines}"
                            ReadOnlySelectedItems="{Binding SelectedItems,
                                                            Mode=OneWayToSource}"
                            SelectedIndex="{Binding SelectedIndex}"
                            SelectionMode="Extended"
                            View="{Binding CustomView}"
                            VirtualizingStackPanel.IsVirtualizing="True"
                            VirtualizingStackPanel.VirtualizationMode="Recycling"
                            be:ListMouseMultiSelectionBehavior.Enabled="True"
                            controls:HighlightedTextBlock.HighlightedText="{Binding HighlightedText}"
                            controls:HighlightedTextBlock.IsCaseSensitive="{Binding IsCaseSensitive}">

                <be:ListMouseMultiSelectionBehavior.SelectionRectangleBrush>
                    <x:Static Member="SystemColors.HighlightBrush" />
                </be:ListMouseMultiSelectionBehavior.SelectionRectangleBrush>
                <be:ListMouseMultiSelectionBehavior.SelectionRectanglePen>
                    <Pen Brush="Black" Thickness="1" />
                </be:ListMouseMultiSelectionBehavior.SelectionRectanglePen>
                <infra:ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Tag="{Binding SelectedItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type infra:ListView}}}" infracontrols:NavigateToLineBehavior.NavigateToLineRequest="{Binding NavigateToLineRequest}">
                            <VirtualizingStackPanel.ContextMenu>
                                <ContextMenu infra:AvalonRegion.Name="ContextMenu">
                                    <MenuItem Command="Copy" />
                                    <MenuItem Command="{Binding AddToScratchPad}"
                                              CommandParameter="{Binding PlacementTarget.Tag,
                                                                         RelativeSource={RelativeSource FindAncestor,
                                                                                                        AncestorType={x:Type ContextMenu}}}"
                                              Header="Add to scratch pad" />

                                    <MenuItem Header="Exclude" Visibility="{Binding CanFilter, Converter={StaticResource BooleanToVisibilityConverter}}">
                                        <MenuItem.ItemsSource>
                                            <MultiBinding Converter="{index:MetaInfoToMenuItemsConverter}">
                                                <Binding Path="MetaInformation" />
                                                <Binding Path="ExcludeCommand" />
                                                <Binding Path="SelectedItems" />
                                            </MultiBinding>
                                        </MenuItem.ItemsSource>
                                    </MenuItem>

                                    <MenuItem Header="Include" Visibility="{Binding CanFilter, Converter={StaticResource BooleanToVisibilityConverter}}">
                                        <MenuItem.ItemsSource>
                                            <MultiBinding Converter="{index:MetaInfoToMenuItemsConverter}">
                                                <Binding Path="MetaInformation" />
                                                <Binding Path="IncludeCommand" />
                                                <Binding Path="SelectedItems" />
                                            </MultiBinding>
                                        </MenuItem.ItemsSource>
                                    </MenuItem>

                                    <MenuItem Command="{Binding ClearFiltersCommand}"
                                              Header="Clear Filters"
                                              IsEnabled="{Binding IsFiltersEnabled}"
                                              Visibility="{Binding CanFilter,
                                                                   Converter={StaticResource BooleanToVisibilityConverter}}" />

                                </ContextMenu>
                            </VirtualizingStackPanel.ContextMenu>
                        </VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                </infra:ListView.ItemsPanel>
            </infra:ListView>
        </dec:DecoratorContentControl>
    </Grid>
</UserControl>